#!/usr/bin/env python3
"""
太阳辐照预测实验脚本
展示如何使用不同的参数配置运行LSTM模型
"""

import subprocess
import sys
import os

def run_experiment(name, cmd_args):
    """运行实验"""
    print(f"\n{'='*50}")
    print(f"运行实验: {name}")
    print(f"{'='*50}")
    
    cmd = ["python", "solar_radiation_lstm.py"] + cmd_args
    print(f"执行命令: {' '.join(cmd)}")
    
    try:
        result = subprocess.run(cmd, capture_output=True, text=True, timeout=3600)  # 1小时超时
        print("标准输出:")
        print(result.stdout)
        if result.stderr:
            print("错误输出:")
            print(result.stderr)
        return result.returncode == 0
    except subprocess.TimeoutExpired:
        print("实验超时")
        return False
    except Exception as e:
        print(f"运行实验时出错: {e}")
        return False

def main():
    """主函数"""
    experiments = [
        {
            "name": "基础配置 (5天输入，1天输出)",
            "args": [
                "--input_window", "120",  # 5天 * 24小时
                "--output_window", "24",  # 1天
                "--hidden_size", "128",
                "--num_layers", "2",
                "--batch_size", "32",
                "--num_epochs", "50",
                "--learning_rate", "0.001"
            ]
        },
        {
            "name": "长窗口配置 (7天输入，2天输出)",
            "args": [
                "--input_window", "168",  # 7天 * 24小时
                "--output_window", "48",  # 2天
                "--hidden_size", "256",
                "--num_layers", "3",
                "--batch_size", "16",
                "--num_epochs", "50",
                "--learning_rate", "0.0005"
            ]
        },
        {
            "name": "短窗口配置 (3天输入，12小时输出)",
            "args": [
                "--input_window", "72",   # 3天 * 24小时
                "--output_window", "12",  # 12小时
                "--hidden_size", "64",
                "--num_layers", "1",
                "--batch_size", "64",
                "--num_epochs", "50",
                "--learning_rate", "0.002"
            ]
        },
        {
            "name": "高精度配置 (5天输入，1天输出，更多参数)",
            "args": [
                "--input_window", "120",  # 5天 * 24小时
                "--output_window", "24",  # 1天
                "--hidden_size", "512",
                "--num_layers", "4",
                "--batch_size", "16",
                "--num_epochs", "100",
                "--learning_rate", "0.0001",
                "--dropout", "0.3"
            ]
        }
    ]
    
    print("太阳辐照预测实验")
    print("将运行以下实验配置:")
    
    for i, exp in enumerate(experiments, 1):
        print(f"{i}. {exp['name']}")
    
    # 运行所有实验
    results = []
    for exp in experiments:
        success = run_experiment(exp["name"], exp["args"])
        results.append((exp["name"], success))
    
    # 打印结果总结
    print(f"\n{'='*50}")
    print("实验结果总结:")
    print(f"{'='*50}")
    
    for name, success in results:
        status = "成功" if success else "失败"
        print(f"{name}: {status}")
    
    success_count = sum(1 for _, success in results if success)
    print(f"\n总实验数: {len(results)}")
    print(f"成功实验数: {success_count}")
    print(f"成功率: {success_count/len(results)*100:.1f}%")

if __name__ == "__main__":
    main() 